package com.hs.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Coursetype;
import com.hs.sfzy.mapper.CoursetypeMapper;
import com.hs.sfzy.service.CoursetypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @BelongsProject: sfzyBackEnd
 * @BelongsPackage: com.hs.sfzy.service.impl
 * @ClassName CoursetypeServiceImpl
 * @Author: 陈千鱼不是鱼
 * @CreateTime: 2024-10-25  20:47
 * @Description: TODO
 * @Version: 1.0
 */
@Service
@RequiredArgsConstructor
public class CoursetypeServiceImpl implements CoursetypeService {

    private final CoursetypeMapper coursetypeMapper;


    @Override
    public List<Coursetype> findAll() {
        return coursetypeMapper.findALl();
    }

    @Override
    public PageInfo<Coursetype> page(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum,pageSize);
        List<Coursetype> list = coursetypeMapper.page(name);
        PageInfo<Coursetype> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void save(Coursetype coursetype) {
        int i = coursetypeMapper.save(coursetype);
        if (i == 0){
            throw new RuntimeException("添加失败");
        }
    }

    @Override
    public void deleteById(Integer id) {
        int i = coursetypeMapper.deleteById(id);
        if (i == 0){
            throw new RuntimeException("删除失败");
        }
    }

    @Override
    public void update(Coursetype coursetype) {
        int i = coursetypeMapper.update(coursetype);
        if (i == 0){
            throw new RuntimeException("更新失败");
        }
    }
}
